<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/jsp/declare.jsp" %>

<!DOCTYPE html>
<html>
<head>
	<base href="<%=basePath %>" />
	<title>床-编辑</title>
	<%@ include file="/common/jsp/common.jsp" %>
	
	<script>
	function rowEdit() {
		redirect("mvc/master/bedList.htm");
	}
	function validate(form) {
		var success = true;
		$(form).find("input").each(function(){
			if (success && !$(this).val()) {
				var _input = this;
				jAlert("请填写完整信息", function(){
					_input.focus();
				});
				success = false;
			}
		});
		return success;
	}
	
	function deleteBed() {
		jConfirm("确认删除？", function(yes){
			if (!yes)
				return;
			
			doAjax({
				url: addFromUserName("mvc/master/${!empty communityId ? communityId : param.communityId }/${!empty roomId ? roomId : param.roomId }/${!empty bed and !empty bed.id ? bed.id : 0}/bedDel.json"),
				data: {
					communityId: "${param.communityId }",
					roomId: "${!empty roomId ? roomId : param.roomId }",
					bedId: "${bed.id }"
				},
				success: function(json){
					if (json && json.msg){
						jAlert(json.msg, function(){
							redirect("mvc/master/${!empty communityId ? communityId : param.communityId }/${!empty roomId ? roomId : param.roomId }/bedList.htm");
						});
					} else {
						jAlert("删除失败");
					}
				}
			});
		});
	}
	</script>
</head>
<body id="room" class="bg-grey">
	<div class="picBar">
		<img src="aizu/images/room/room.jpg" />
	</div>
	<form action="mvc/master/${!empty communityId ? communityId : param.communityId }/${!empty roomId ? roomId : param.roomId }/${!empty bed and !empty bed.id ? bed.id : 0}/bedEdit.htm"
		method="post" onsubmit="return validate(this);">
		<input type="hidden" name="fromUserName" value="${param.fromUserName }" />
		<input type="hidden" name="deposit" value="0" />
		<div class="frame">
			<div class="row">
				<div class="input" placeholder="地址">${address }</div>
			</div>
			<div class="row">
				<div class="input" placeholder="房号">${roomName }</div>
			</div>
			<div class="row">
				<input name="bed_num" value="${bed.bed_num }" class="input" placeholder="输入床号" />
			</div>
			<%-- <div class="row">
				<input name="bed_price" value="${bed.bed_price }" class="input" placeholder="输入出租价格" />
			</div>
			<div class="row">
				<input name="deposit" value="${bed.deposit }" class="input" placeholder="输入押金（月）" />
			</div> --%>
		</div>
		<div class="button-bar center">
			<input type="submit" value="保存" class="submit" />
			<c:if test="${!empty bed and !empty bed.id }">
			<input type="button" value="删除" class="delete" onclick="deleteBed()" />
			</c:if>
		</div>
	</form>
</body>
</html>